#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
int jiance[maxn];

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--)
    {
        int n, m, L, V, chaosu = 0;
        cin>>n>>m>>L>>V;
        for(int i = 1;i <= n;i++)
        {
            int d, v, a;
            cin>>d>>v>>a;
            if(v > V)  chaosu++;
        }
        for(int i = 1;i <= m;i++)  cin>>jiance[i];
        cout<<chaosu<<" "<<m - 1<<endl;
    }
    return 0;
}
